package partition;

import network.Network;
import network.Port;
import networkLoader.FabricNetwork;
import verifier.util.BDDEngine;

import java.util.HashMap;

public class AbstractNetwork {
    private HashMap<Port, Integer> portToPred;
    private HashMap<String, Partition> partitions;
    private Network network;
    private BDDEngine bddEngine;
    public Network originNet;
    private HashMap<Port, HashMap<Port, Integer>> ecmap = new HashMap<>();

    public AbstractNetwork(HashMap<String, Partition> partitions) {
        this.partitions = partitions;
        this.portToPred = new HashMap<>();
        this.bddEngine = new BDDEngine(32);
        Network n = new Network("Abstract");
        this.network = n;
    }

//    public void allPairReach() {
////        Port src = originNet.getDevice(String.format("rsw-%d-%d", 0, 0)).getPort(String.format("rsw-%d-%d>h-%d-%d", 0, 0, 0, 0));
////        Port dst = originNet.getDevice(String.format("rsw-%d-%d", 1, 0)).getPort(String.format("rsw-%d-%d>h-%d-%d", 1, 0, 1, 0));
////        aggr();
////        this.bddEngine = new BDDEngine(32);
//        for (int iPod = 0; iPod < 112; iPod++) {
//            for (int iHost = 0; iHost < 48; iHost++) {
//                Port port = originNet.getDevice(String.format("rsw-%d-%d", iPod, iHost)).getPort(String.format("rsw-%d-%d>h-%d-%d", iPod, iHost, iPod, iHost));
//                long start = System.nanoTime();
//                traverseReachSrc(port, 1, port);
//                System.out.println("check all reachable of " + port.getName() + " takes: " + (System.nanoTime() - start));
////                return;
//            }
//        }
//    }

//    private void traverseReachSrc(Port port, int hs, Port origin) {
//        if (hs == 0) {
//            return;
//        }
//        if (port != origin && port.getName().startsWith("h")) {
//            System.out.println(origin.getName() + " can reach " + port.getName() + " by: " + hs);
////            bddEngine.bdd.printSet(hs);
//            return;
//        }
//        ArrayList<LocalTask> localTasks = port.getPartition().getLocalTasksByIngress(port);
//        for (LocalTask localTask : localTasks) {
//            if (localTask.getHsbytes() == null) {
//                break;
//            }
//            int tbdd = Util.crossBDDLoad(port.getPartition().getVerifier().bddEngine.getBdd(), localTask.getHsbytes(), this.bddEngine.getBdd());
//            int tmp = this.bddEngine.and(tbdd, hs);
//            this.bddEngine.ref(tmp);
//            traverseReachSrc(localTask.getEgress().getPeer(), tmp, origin);
//            this.bddEngine.deref(tmp);
//        }
//    }

    public static void main(String[] args) {
        long x = 0;
        for (int i = 0; i < 54400; i++) {
            for (int j = 0; j < 54400; j++) {
                for (int k = 0; k < 54400; k++) {
                    x += 1;
                }
            }
            System.out.println(i);
        }
        System.out.println(x);
        System.exit(1);
        Network network = FabricNetwork.getNetwork(112);
        AbstractNetwork an = new AbstractNetwork(FabricNetwork.setupPartitions(network));

    }
}
